#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "ioc\handlerRemoveAll.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);

private ["_namespace","_event","_removed"];
DEFAULT_PARAM(_namespace,0,"");
DEFAULT_PARAM(_event,1,"");

_removed = 0;
if (IS_STRING(_namespace) && {_namespace != ""}) then {
	_idx = GVAR(NAMESPACES) find toLower(_namespace);
	if (_idx >= 0) then {
		if (IS_STRING(_event)) then {
			if (_event == "") then {
				_removed = count (GVAR(EVENTS) select _idx);
				GVAR(NAMESPACES) set [_idx, "XxDelxX"];
				GVAR(NAMESPACE_PVEH) set [_idx, "XxDelxX"];
				GVAR(EVENTS) set [_idx, "XxDelxX"];
				GVAR(HANDLERS) set [_idx, "XxDelxX"];
				GVAR(HANDLERS) = GVAR(HANDLERS) - ["XxDelxX"];
				GVAR(EVENTS) = GVAR(EVENTS) - ["XxDelxX"];
				GVAR(NAMESPACE_PVEH) = GVAR(NAMESPACE_PVEH) - ["XxDelxX"];
				GVAR(NAMESPACES) = GVAR(NAMESPACES) - ["XxDelxX"];
				TRACE_1("Removed Namespace Events",_removed);
			} else {
				_events = GVAR(EVENTS) select _idx;
				_evt_idx = _events find toLower(_event);
				if (_evt_idx >= 0) then {
					_handlers = (GVAR(HANDLERS) select _idx);
					_removed = count _handlers;
					_handlers set [_evt_idx, "XxDelxX"];
					_handlers = _handlers - ["XxDelxX"];
					_events set [_evt_idx,"XxDelxX"];
					_events = _events - ["XxDelxX"];
					GVAR(HANDLERS) set [_idx, _handlers];
					GVAR(EVENTS) set [_idx, _events];
					TRACE_1("Removed Event Handlers",_removed);
				} else {
					DEBUG_1("Event not found",_this);
				};
			};
		} else {
			DEBUG_1("Invalid Input",_this);
		};
	} else {
		DEBUG_1("Namespace not found",_this);
	};
} else {
	DEBUG_1("Invalid Input",_this);
};
TRACE_1("End",_removed);
_removed;